package ssau.knyazev.modules;

import ssau.knyazev.core.Complex;

public class Helper {

	private Helper(){}
	
	public static Complex[] transformFloat(float[] arr) {
		Complex[] res = new Complex[arr.length];
		for (int i = 0; i < arr.length; i++)
			res[i] = new Complex(arr[i], 0);
		return res;
	}
	
	public static Complex[][] transformFloat(float[][] arr) {
		Complex[][] res = new Complex[arr.length][arr[0].length];
		for (int i = 0; i < arr.length; i++)
			for (int j = 0; j < arr[0].length; j++)
				res[i][j] = new Complex(arr[i][j], 0);
		return res;
	}

	public static Object[][] inverse(Object[][] src){
		int N = src.length;
		for (int i = 0; i < N; i++){
			inverse(src[i]);
		}
		Object[] arr = new Object[N];
		for (int i = 0; i < N; i++){
			for (int j = 0; j < N; j++){
				arr[j] = src[j][i];
			}
			inverse(arr);
			for (int j = 0; j < N; j++){
				src[j][i] = arr[j];
			}
		}
		return src;
	}
	
	public static void inverse(Object[] src){
		int dl = src.length/2;
		int st = src.length - 1;
		int j = 0;
		for (int i = 0; i < st; i++){
			if (i < j){
				Object s0 = src[i];
				src[i] = src[j];
				src[j] = s0;
			}
			int k = dl;
			while (k <= j){
				j = j - k;
				k = k >> 1;
			}
			j = j + k;
		}
	}
	
}
